package com.breaktian.demoapp.ui.refreshdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.breaktian.assemble.refresh.superrefresh.PullDownRefreshLayout;
import com.breaktian.assemble.refresh.superrefresh.PullRefreshLayout;
import com.breaktian.assemble.utils.ThreadUtil;
import com.breaktian.assemble.webview.ProgressWebView;
import com.breaktian.demoapp.R;

public class WebviewActivity extends AppCompatActivity {

    private PullDownRefreshLayout pullRefreshLayout;
    private ProgressWebView webview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview2);

        pullRefreshLayout = (PullDownRefreshLayout)findViewById(R.id.pullRefreshLayout);

        pullRefreshLayout.setOnPulldownRefreshListener(new PullRefreshLayout.OnPullDownRefreshListener() {
            @Override
            public void onPullDown() {
                ThreadUtil.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        webview.reload();
                    }
                });

            }
        });
        webview = (ProgressWebView)findViewById(R.id.webview);
        webview.loadUrl("http://www.vip.com");
        webview.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                pullRefreshLayout.stopPullDownRefresh();
                super.onPageFinished(view, url);
            }
        });

    }
}
